//
//  MainBackViewController.m
//  好听-1
//
//  Created by luojin on 15/4/13.
//  Copyright (c) 2015年 MyCompany. All rights reserved.
//

#import "MainBackViewController.h"
#import "CollectViewController.h"
#import "UserViewController.h"
#import "LocalStoreViewController.h"

#define SCREEN_X 375
#define SCREEN_Y 667

@interface MainBackViewController ()

@end

@implementation MainBackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    [self creatLeftButtons];
    [self creatScroll];
}

#pragma mark -
#pragma mark 创建navigation上面的按钮  实现我的, 精选... 的页面滑动
- (void)creatLeftButtons
{
    UIBarButtonItem *collectButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"侧拉栏"] style:UIBarButtonItemStyleDone target:self action:@selector(collectButtonAction:)];
    UIBarButtonItem *userButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"user"] style:UIBarButtonItemStyleDone target:self action:@selector(userButtonAction:)];
    UIBarButtonItem *localButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"设置"] style:UIBarButtonItemStyleDone target:self action:@selector(localButtonAction:)];
    
    self.navigationItem.leftBarButtonItems = @[collectButton, userButton, localButton];
    
    [collectButton release];
    [userButton release];
    [localButton release];
}

- (void)creatScroll
{
    _scroll = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    _scroll.contentSize = CGSizeMake(SCREEN_X * 3, 0);
    [_scroll setBounces:NO];
    [_scroll setPagingEnabled:YES];
    
    [self.view addSubview:_scroll];
    [_scroll release];
    
    CollectViewController *collect = [[CollectViewController alloc] init];
    collect.view.frame = CGRectMake(0, 0, SCREEN_X, SCREEN_Y);
    [_scroll addSubview:collect.view];

    UserViewController *user = [[UserViewController alloc] init];
    user.view.frame = CGRectMake(SCREEN_X, 0, SCREEN_X, SCREEN_Y);
    [_scroll addSubview:user.view];

    LocalStoreViewController *local = [[LocalStoreViewController alloc] init];
    local.view.frame = CGRectMake(SCREEN_X * 2, 0, SCREEN_X, SCREEN_Y);
    [_scroll addSubview:local.view];
}

- (void)collectButtonAction:(UIBarButtonItem *)sender
{
    [_scroll setContentOffset:CGPointMake(0, 0)];
}

- (void)userButtonAction:(UIBarButtonItem *)sender
{
    [_scroll setContentOffset:CGPointMake(SCREEN_X, 0)];
}

- (void)localButtonAction:(UIBarButtonItem *)sender
{
    [_scroll setContentOffset:CGPointMake(SCREEN_X * 2, 0)];
}

@end
